<<<<<<< HEAD
<?php 
function render_goal_widget($goal) {
?>
<div class="span4 show-grid">
    <div class="well">
        <h3><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name'];?></a></h3>
        <p><?php echo $goal['started_on'];?> ~ <?php echo $goal['ended_on'];?></p>
        <div class="btn-toolbar">
        <?php 
        if ($goal['status'] == 'active') {
            echo '<a class="btn btn-danger" href="/'.APP_CONTEXT.'/modules/goal/end.php?id='.$goal['id'].'">结束</a>';
        } else {
            echo '<a class="btn btn-success" href="/'.APP_CONTEXT.'/modules/goal/activate.php?id='.$goal['id'].'">开始</a>';
        }
        echo ' <a class="btn btn-primary" href="/'.APP_CONTEXT.'/modules/goal/edit.php?id='.$goal['id'].'">编辑</a>';
        ?>
        </div>
    </div>
</div>
<?php
}

function render_goal_menu($active_idx) {
    require_once dirname(__FILE__).'/../service/StaticsService.php';
    $staticsService = new StaticsService();
    $statics = $staticsService->getUserGoalStatics();
    $status = array();
    $total = 0;
    foreach ($statics as $st) {
        $status[$st['status']] = $st['count'];
        $total += $st['count'];
    }
    $status['all'] = $total;
?>
<div class="subnav">
  <ul class="nav nav-pills">
    <li <?php if ($active_idx == 3) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/goals.php">所有目标<span class="badge"><?php echo $status['all'];?></span></a></li>
    <li <?php if ($active_idx == 1) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/success-goals.php">成功的目标<span class="badge badge-success"><?php echo isset($status['success']) ? $status['success'] : 0;?></span></a></li>
    <li <?php if ($active_idx == 2) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/failed-goals.php">失败的目标<span class="badge badge-error"><?php echo isset($status['fail']) ? $status['fail'] : 0;?></span></a></li>
    <li <?php if ($active_idx == 4) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/new-goal.php">开始制定新目标</a></li>
  </ul>
</div>
<?php
}

function render_goal_list($goals) {
?>
<div class="span12">
    <table class="table table-striped table-bordered table-condensed">
        <tr>
            <th>目标</th>
            <th>类型</th>
            <th>状态</th>
            <th>开始日期</th>
            <th>结束日期</th>
            <th>进度</th>
            <th>操作</th>
        </tr>
        <?php
        foreach ($goals as $goal) {
        ?>
        <tr>
            <td><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name']?></a></td>
            <td>习惯养成</td>
            <td><?php echo $goal['status'];?></td>
            <td><?php echo $goal['started_on'];?></td>
            <td><?php echo $goal['ended_on'];?></td>
            <td></td>
            <td>
            <?php
            echo ' <a class="btn btn-primary" href="/'.APP_CONTEXT.'/modules/goal/edit.php?id='.$goal['id'].'">编辑</a>';
            if ($goal['status'] == 'new') {
                echo ' <a class="btn btn-success" href="/'.APP_CONTEXT.'/modules/goal/activate.php?id='.$goal['id'].'">开始</a>';
            }
            if ($goal['status'] == 'active') {
                echo ' <a class="btn btn-danger" href="/'.APP_CONTEXT.'/modules/goal/end.php?id='.$goal['id'].'">终止</a>';
            }
            ?>
            </td>
        </tr>
        <?php
        }
        ?>
    </table>
</div>
<?php
}

function render_goals_today($goal) {
    require_once dirname(__FILE__).'/../service/ActivityService.php';
    require_once dirname(__FILE__).'/../service/UserService.php';
    $activityService = new ActivityService();
    $userService = new UserService();
    $user = $userService->getCurrentUser();
    $day = date('Y-m-d');
    $activity = $activityService->getActivityOfDay($user['id'], $goal['id'], $day);
    
    $started_on = strtotime(substr($goal['started_on'], 0, 10));
    $today = strtotime($day);
    $daycount = round(($today - $started_on) / 3600 / 24) + 1;
    
?>
<div class="span4">
    <div class="well">
        <h3><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name'];?></a></h3>
        <p><span>今天（<?php echo $day;?>）是该目标执行第<?php echo $daycount?>天，完成如何？</span></p>
        <?php 
        if ($activity) {
            echo '<a href="#" class="btn btn-primary disabled">'.$activity['status'].'</a>';
        } else {
        ?>
        <div class="btn-toolbar">
            <a class="btn btn-success" href="#" onclick="doSuccess(<?php echo $goal['id'];?>)">成功</a>
            <a class="btn btn-danger" href="#" onclick="doFail(<?php echo $goal['id'];?>)">失败</a>
        </div>
        <?php 
        }
        ?>
    </div>
</div>
<?php
}
=======
<?php 
function render_goal_widget($goal) {
?>
<div class="span4 show-grid">
    <div class="well">
        <h3><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name'];?></a></h3>
        <p><?php echo $goal['started_on'];?> ~ <?php echo $goal['ended_on'];?></p>
        <div class="btn-toolbar">
        <?php 
        if ($goal['status'] == 'active') {
            echo '<a class="btn btn-danger" href="/'.APP_CONTEXT.'/modules/goal/end.php?id='.$goal['id'].'">结束</a>';
        } else {
            echo '<a class="btn btn-success" href="/'.APP_CONTEXT.'/modules/goal/activate.php?id='.$goal['id'].'">开始</a>';
        }
        echo ' <a class="btn btn-primary" href="/'.APP_CONTEXT.'/modules/goal/edit.php?id='.$goal['id'].'">编辑</a>';
        ?>
        </div>
    </div>
</div>
<?php
}

function render_goal_menu($active_idx) {
    require_once dirname(__FILE__).'/../service/StaticsService.php';
    $staticsService = new StaticsService();
    $statics = $staticsService->getUserGoalStatics();
    $status = array();
    $total = 0;
    foreach ($statics as $st) {
        $status[$st['status']] = $st['count'];
        $total += $st['count'];
    }
    $status['all'] = $total;
?>
<div class="subnav">
  <ul class="nav nav-pills">
    <li <?php if ($active_idx == 3) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/goals.php">所有目标<span class="badge"><?php echo $status['all'];?></span></a></li>
    <li <?php if ($active_idx == 1) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/success-goals.php">成功的目标<span class="badge badge-success"><?php echo isset($status['success']) ? $status['success'] : 0;?></span></a></li>
    <li <?php if ($active_idx == 2) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/failed-goals.php">失败的目标<span class="badge badge-error"><?php echo isset($status['fail']) ? $status['fail'] : 0;?></span></a></li>
    <li <?php if ($active_idx == 4) {echo 'class="active"';}?>><a href="/<?php echo APP_CONTEXT;?>/new-goal.php">开始制定新目标</a></li>
  </ul>
</div>
<?php
}

function render_goal_list($goals) {
?>
<div class="span12">
    <table class="table table-striped table-bordered table-condensed">
        <tr>
            <th>目标</th>
            <th>类型</th>
            <th>状态</th>
            <th>开始日期</th>
            <th>结束日期</th>
            <th>进度</th>
            <th>操作</th>
        </tr>
        <?php
        foreach ($goals as $goal) {
        ?>
        <tr>
            <td><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name']?></a></td>
            <td>习惯养成</td>
            <td><?php echo $goal['status'];?></td>
            <td><?php echo $goal['started_on'];?></td>
            <td><?php echo $goal['ended_on'];?></td>
            <td></td>
            <td>
            <?php
            echo ' <a class="btn btn-primary" href="/'.APP_CONTEXT.'/modules/goal/edit.php?id='.$goal['id'].'">编辑</a>';
            if ($goal['status'] == 'new') {
                echo ' <a class="btn btn-success" href="/'.APP_CONTEXT.'/modules/goal/activate.php?id='.$goal['id'].'">开始</a>';
            }
            if ($goal['status'] == 'active') {
                echo ' <a class="btn btn-danger" href="/'.APP_CONTEXT.'/modules/goal/end.php?id='.$goal['id'].'">终止</a>';
            }
            ?>
            </td>
        </tr>
        <?php
        }
        ?>
    </table>
</div>
<?php
}

function render_goals_today($goal) {
    require_once dirname(__FILE__).'/../service/ActivityService.php';
    require_once dirname(__FILE__).'/../service/UserService.php';
    $activityService = new ActivityService();
    $userService = new UserService();
    $user = $userService->getCurrentUser();
    $day = date('Y-m-d');
    $activity = $activityService->getActivityOfDay($user['id'], $goal['id'], $day);
    
    $started_on = strtotime(substr($goal['started_on'], 0, 10));
    $today = strtotime($day);
    $daycount = round(($today - $started_on) / 3600 / 24) + 1;
    
?>
<div class="span4">
    <div class="well">
        <h3><a href="/<?php echo APP_CONTEXT;?>/goal.php?id=<?php echo $goal['id'];?>"><?php echo $goal['name'];?></a></h3>
        <p><span>今天（<?php echo $day;?>）是该目标执行第<?php echo $daycount?>天，完成如何？</span></p>
        <?php 
        if ($activity) {
            echo '<a href="#" class="btn btn-primary disabled">'.$activity['status'].'</a>';
        } else {
        ?>
        <div class="btn-toolbar">
            <a class="btn btn-success" href="#" onclick="doSuccess(<?php echo $goal['id'];?>)">成功</a>
            <a class="btn btn-danger" href="#" onclick="doFail(<?php echo $goal['id'];?>)">失败</a>
        </div>
        <?php 
        }
        ?>
    </div>
</div>
<?php
}
>>>>>>> 20d6c557d209a3f376420616f57b4bd953611975
?>